package command;

import roborally.Direction;
import elements.Robot;
/**
 * A class of basic command representing the turn operation.
 * 
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 */
public class Turn extends BasicCommand {
	/**
	 * Initialize the new Turn with the given direction.
	 * @param 	direction
	 * 			The direction for the new Turn.
	 * @post	The given direction will be the same as the direction from the new Turn.
	 */
	public Turn(Direction direction){
		this.direction = direction;
	}
	
	/**
	 * The direction of the turn.
	 */
	private Direction direction;
	
	/**
	 * Returns the direction of the Turn.
	 * @return	the direction of the Turn
	 */
	private Direction getDirection(){
		return this.direction;
	}
	
	/**
	 * Turns the robot once to the given direction if he has enough energy.
	 * @effect 	If the robot has enough energy it will be turned with the given direction.
	 */
	@Override
	public void execute(Robot robot) {
		if(robot.isLegalEnergy(robot.getEnergy().subtractAndReturn(Robot.getEnergyForTurn()))){
			robot.turn(this.getDirection());
		}
	}
	
	@Override
	public String toString(){
		return "( turn " + this.getDirection().toString() + ")";
	}
	
	@Override
	public boolean equals(Object object){
		if(object == null || this==null){
			return false;
		}
		return this.toString().equals(object.toString());
	}
}
